import matplotlib.pyplot as plt
import pandas as pd
import numpy as np

file_path = 'd:\\BaiduNetdiskDownload\\美赛赛题合集\\2023年美赛赛题\\2023\\第一问\\单词属性.xlsx'
data = pd.read_excel(file_path)
X=data['元音占比']
Y=data['困难占比']
plt.figure(figsize=(7, 5))
plt.scatter(Y, X, alpha=0.7,c = 'red')
plt.xlabel('Proportion of difficulties')
plt.ylabel('Vowel ratio')
plt.title('Vowel')
plt.savefig('d:\\BaiduNetdiskDownload\\美赛赛题合集\\2023年美赛赛题\\2023\\第一问\\Vowel.png')
plt.show()

X=data['常用字母占比']
Y=data['困难占比']
plt.figure(figsize=(7, 5))
plt.scatter(Y, X, alpha=0.7, c = 'yellow')
plt.xlabel('Proportion of difficulties')
plt.ylabel('Common letters ratio')
plt.title('Common')
plt.savefig('d:\\BaiduNetdiskDownload\\美赛赛题合集\\2023年美赛赛题\\2023\\第一问\\Common.png')
plt.show()

X=data['非常用字母占比']
Y=data['困难占比']
plt.figure(figsize=(7, 5))
plt.scatter(Y, X, alpha=0.7, c = 'green')
plt.xlabel('Proportion of difficulties')
plt.ylabel('unCommon letters ratio')
plt.title('unCommon')
plt.savefig('d:\\BaiduNetdiskDownload\\美赛赛题合集\\2023年美赛赛题\\2023\\第一问\\unCommon.png')
plt.show()

X=data['重复字母数目']
Y=data['困难占比']
plt.figure(figsize=(7, 5))
plt.scatter(Y, X, alpha=0.7, c = 'orange')
plt.xlabel('Proportion of difficulties')
plt.ylabel('Number of duplicate letters')
plt.title('Number of duplicate')
plt.savefig('d:\\BaiduNetdiskDownload\\美赛赛题合集\\2023年美赛赛题\\2023\\第一问\\Number of duplicate.png')
plt.show()

X=data['Tag']
Y=data['困难占比']
plt.figure(figsize=(7, 5))
plt.scatter(Y, X, alpha=0.7, c = 'purple')
plt.xlabel('Proportion of difficulties')
plt.ylabel('Tag')
plt.title('Tag')
plt.savefig('d:\\BaiduNetdiskDownload\\美赛赛题合集\\2023年美赛赛题\\2023\\第一问\\Tag.png')
plt.show()
# import pandas as pd
# import numpy as np
# import matplotlib.pyplot as plt
# import seaborn as sns
# from sklearn.model_selection import train_test_split
# from sklearn.linear_model import LinearRegression
# from sklearn.preprocessing import PolynomialFeatures
# from sklearn.metrics import mean_squared_error
# from sklearn.preprocessing import StandardScaler

# # 读取Excel文件
# file_path = 'd:\\BaiduNetdiskDownload\\美赛赛题合集\\2023年美赛赛题\\2023\\第一问\\单词属性.xlsx'
# data = pd.read_excel(file_path)

# # 提取自变量和因变量
# X = data[['元音占比', '重复字母数目', '常用字母占比', '非常用字母占比']]
# y = data['困难占比']
# scaler = StandardScaler()
# X = scaler.fit_transform(X)

# # 分割数据集为训练集和测试集
# X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

# # 线性回归模型
# linear_model = LinearRegression()
# linear_model.fit(X_train, y_train)
# y_pred_linear = linear_model.predict(X_test)

# # 计算线性回归模型的均方误差
# mse_linear = mean_squared_error(y_test, y_pred_linear)
# print(f'线性回归模型的均方误差: {mse_linear}')

# # 非线性回归模型（多项式回归）
# poly_features = PolynomialFeatures(degree=2)
# X_train_poly = poly_features.fit_transform(X_train)
# X_test_poly = poly_features.transform(X_test)

# nonlinear_model = LinearRegression()
# nonlinear_model.fit(X_train_poly, y_train)
# y_pred_nonlinear = nonlinear_model.predict(X_test_poly)

# # 计算非线性回归模型的均方误差
# mse_nonlinear = mean_squared_error(y_test, y_pred_nonlinear)
# print(f'非线性回归模型的均方误差: {mse_nonlinear}')

# # 可视化结果
# plt.figure(figsize=(14, 7))

# plt.subplot(1, 2, 1)
# plt.scatter(y_test, y_pred_linear, alpha=0.7)
# plt.xlabel('true')
# plt.ylabel('per(linear)')
# plt.title('线性回归预测结果')

# plt.subplot(1, 2, 2)
# plt.scatter(y_test, y_pred_nonlinear, alpha=0.7)
# plt.xlabel('真实值')
# plt.ylabel('预测值 (非线性回归)')
# plt.title('非线性回归预测结果')

# plt.tight_layout()
# plt.show()